package io.renren.modules.avanotes.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.avanotes.entity.ReviewScheduleEntity;
import io.renren.modules.avanotes.service.ReviewScheduleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Arrays;
import java.util.Map;


/**
 * 复习计划表
 *
 * @author zzr
 * @email 529742454@qq.com
 * @date 2022-02-27 21:55:28
 */
@RestController
@RequestMapping("avanotes/reviewschedule")
@Api("复习计划表接口")
public class ReviewScheduleController {
    @Autowired
    private ReviewScheduleService reviewScheduleService;

    //region 自定义业务

    /**
     * 展示专题名称
     *
     * @param params
     * @return
     */
    @PostMapping("/listOrderByDay")
    //@RequiresPermissions("avanotes:reviewschedule:list")
    //@ApiImplicitParams({
    //        @ApiImplicitParam(name = "page", value = "当前页码", paramType = "query", dataType = "String"),
    //        @ApiImplicitParam(name = "limit", value = "每页记录数", paramType = "query", dataType = "String"),
    //        @ApiImplicitParam(name = "key", value = "检索关键字", paramType = "query", dataType = "String")
    //})
    @ApiOperation("查询列表（按照执行日期 day 排序）")
    public R listOrderByDay(@ApiIgnore @RequestParam Map<String, Object> params) {
        PageUtils page = reviewScheduleService.queryPageOrderByDay(params);

        //return R.ok().put("page", page);
        return R.ok().setData(page);
    }

    //listToday

    /**
     * 查询用户本日的复习计划
     *
     * @return
     */
    @PostMapping("/listToday")
    public R listToday(@ApiIgnore @RequestParam Map<String, Object> params) {
        PageUtils page = reviewScheduleService.queryPageByToday(params);

        return R.ok().setData(page);
    }

    /**
     * 获取至今仍未复习的计划
     *
     * @param params
     * @return
     */
    @PostMapping("/listUntilToday")
    public R listUntilToday(@ApiIgnore @RequestParam Map<String, Object> params) {
        PageUtils page = reviewScheduleService.queryPageByToday(params);

        return R.ok().setData(page);
    }

    /**
     * 复习打卡
     * 1. 完成复习（修改状态）
     * 2. 更新 EF 的值，计算下一个间隔，创建新的计划
     *
     * @param id
     * @return
     */
    @PostMapping("/attend/{id}/{q}")
    public R attend(@PathVariable("id") Long id, @PathVariable("q") Integer q) {
        reviewScheduleService.attend(id, q);
        return R.ok().setData(true);
    }

    //endregion

    /**
     * 列表
     */
    @PostMapping("/list")
    //@RequiresPermissions("avanotes:reviewschedule:list")
    //@ApiImplicitParams({
    //        @ApiImplicitParam(name = "page", value = "当前页码", paramType = "query", dataType = "String"),
    //        @ApiImplicitParam(name = "limit", value = "每页记录数", paramType = "query", dataType = "String"),
    //        @ApiImplicitParam(name = "key", value = "检索关键字", paramType = "query", dataType = "String")
    //})
    //@ApiOperation("查询列表")
    public R list(@ApiIgnore @RequestParam Map<String, Object> params) {
        PageUtils page = reviewScheduleService.queryPage(params);

        //return R.ok().put("page", page);
        return R.ok().setData(page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    //@RequiresPermissions("avanotes:reviewschedule:info")
    //@ApiOperation("查询单条")
    public R info(@PathVariable("id") Long id) {
        ReviewScheduleEntity reviewSchedule = reviewScheduleService.getById(id);

        //return R.ok().put("reviewSchedule", reviewSchedule);
        return R.ok().setData(reviewSchedule);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    //@RequiresPermissions("avanotes:reviewschedule:save")
    //@ApiOperation("保存")
    public R save(@RequestBody ReviewScheduleEntity reviewSchedule) {
        reviewScheduleService.save(reviewSchedule);

        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    //@RequiresPermissions("avanotes:reviewschedule:update")
    //@ApiOperation("修改")
    public R update(@RequestBody ReviewScheduleEntity reviewSchedule) {
        reviewScheduleService.updateById(reviewSchedule);

        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    //@RequiresPermissions("avanotes:reviewschedule:delete")
    //@ApiOperation("删除")
    public R delete(@RequestBody Long[] ids) {
        reviewScheduleService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
